package com.acorn.community.dao.repository.user;

import com.acorn.community.dao.mapper.user.UserAccountMapper;
import com.acorn.community.entity.user.UserAccountEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 用户账户
 *
 * @author tianshiwei
 */
@Slf4j
@Repository
public class UserAccountRepository {

    @Resource
    private UserAccountMapper userAccountMapper;

    /**
     * 获取用户账户
     *
     * @param userId
     * @return
     */
    public UserAccountEntity getEntityById(Long userId) {
        log.info("UserAccountRepository getEntityById params:{}", userId);

        QueryWrapper<UserAccountEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserAccountEntity::getUserId, userId);
        queryWrapper.last("limit 1");

        UserAccountEntity userAccountEntity = userAccountMapper.selectOne(queryWrapper);

        log.info("UserAccountRepository getEntityById params:{},return:{}", userId, userAccountEntity);
        return userAccountEntity;
    }
}
